# +++/*
import logging

from rest_framework import viewsets
from rest_framework import status
from rest_framework.response import Response
from rest_framework.decorators import action

from .models import Test
from .serializers import TestSerializer

logger = logging.getLogger(__name__)

class TestView(viewsets.ModelViewSet):
    queryset = Test.objects.all()
    serializer_class = TestSerializer

    # GET 请求
    def list(self, request):
        queryset = self.get_queryset()
        serializer = self.get_serializer(queryset, many=True)
        return Response({'code': 20000, 'data': serializer.data, 'message': 'ok'}, status=status.HTTP_200_OK)

    def retrieve(self, request, pk=None):
        my_model = self.get_object()
        serializer = self.get_serializer(my_model)
        return Response({'code': 20000, 'data': serializer.data, 'message': 'ok'}, status=status.HTTP_200_OK)

    # POST 请求
    def create(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({'code': 20000, 'data': serializer.data, 'message': 'ok'}, status=status.HTTP_200_OK)

    # PUT 请求
    def update(self, request, pk=None):
        my_model = self.get_object()
        serializer = self.get_serializer(my_model, data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response({'code': 20000, 'data': serializer.data, 'message': 'ok'}, status=status.HTTP_200_OK)

    # DELETE 请求
    def destroy(self, request, pk=None):
        my_model = self.get_object()
        my_model.delete()
        return Response({'code': 20004, 'data': None, 'message': '处理成功'}, status=status.HTTP_204_NO_CONTENT)

    # 自定义操作
    @action(detail=True, methods=['post'])
    def set_enabled(self, request, pk=None):
        my_model = self.get_object()
        my_model.enabled = request.data['enabled']
        my_model.save()
        serializer = self.get_serializer(my_model)
        return Response({'code': 20000, 'data': serializer.data, 'message': 'ok'}, status=status.HTTP_200_OK)
# */